package com.dyg.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;

public class BaseService {  
    
    protected RedisTemplate<String, Object> redisTemplate;  
      
    protected Logger logger = LoggerFactory.getLogger(this.getClass());  
      
    @Autowired  
    @Qualifier("redisTemplate")  
    public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {  
        this.redisTemplate = redisTemplate;  
    }  
    
    /**
     * 保存指定key值的value
     * @param key
     * @param value
     */
    public void set(String key,Object value){
    	
    	redisTemplate.opsForValue().set(key, value);
    }
    
    /**
     * 得到指定key值的value
     * @param key
     */
    public Object get(String key){
    	
        return redisTemplate.opsForValue().get(key);
    }
    
    /**
     * 删除指定key的value
     * @param key
     */
    public void del(String key){
        redisTemplate.delete(key);
    }
    
    /**
     * 判断key是否存在
     */
    public int exists(String key){
    	Boolean hasKey = redisTemplate.hasKey(key);
    	if(hasKey){
    		return 1;
    	}else{
    		return 0;
    	}
    }
    
      
}